<?php
/**
 * Created by PhpStorm.
 * User: aeball
 * Date: 2017/3/14
 * Time: 19:37
 */

/*
 * 图片管理系统
 * */
namespace app\admin\controller;

use app\common\controller\AdminBase;
// 使用文章的分类
use app\common\model\Category as CategoryModel;
use app\common\model\Photo as PhotoModel;
use think\Db;



class Photo extends AdminBase
{
    protected $photo_model;
    protected $category_model;
    
    /*
     * 初始化分类信息
     * */
    protected function _initialize()
    {
    	parent::_initialize();
    	$this->article_model  = new PhotoModel();
    	$this->category_model = new CategoryModel();
    
    	$category_level_list = $this->category_model->getLevelList();
    	$this->assign('category_level_list', $category_level_list);
    }
    
    /*
     * show all blogs
     * */
    public function index($cid = 0, $keyword = '', $page = 1){


        $photo_model = new PhotoModel();
        $photo_result=  $photo_model->showHomeList($cid,$keyword,$page);

    	return $this->fetch('index', [
    			'article_list' => $photo_result,
    	]);
    }
    /*
     * 添加图片数据
     * */
   
    public function add()
    {
    	return $this->fetch();
    }

    public function images(){
        var_dump($this->request);
    }

    public function save(){
        if ($this->request->isPost()) {
            $data            = $this->request->param();
            // validate 验证数据
            $validate_result = $this->validate($data, 'Photo');

            if ($validate_result !== true) {
                $this->error($validate_result);
                echo '保存失败';
            } else {
                if ($this->photo_model->allowField(true)->save($data)) {
                    //   $this->success('保存成功');
                    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
                    $this->success('新增成功', 'Article/index');
                } else {
                    $this->error('保存失败');
                }
            }
        }
    }
    
    /*
     * 编辑修改图片
     * */
    public function edit(){

    	//is post 
    	if($this->request->isPost()){
    		// if empty id is new 
    		var_dump($this->request);
    		if($this->request->has('id','get')){
    			// edit
    			echo  'edit';
    			var_dump($this->request);
    		}
    		
    	}else {
            return $this->fetch();
    	}

    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


}